{% macro render_tweet(result) -%}
    {% set tweet=prerender_tweet(result) %}
    <div class="status shift">
        <div class="item-header">
            <img class="avatar" src="{{ tweet.user.profile_image_url_https }}"/>
            <span class="bold">
                <a href="{{ url_for("user", screen_name=tweet.user.screen_name) }}">
                    {{ tweet.user.screen_name }} ({{ tweet.user.name }})
                </a>
            </span>
            <span class="actions">
                <a href="{{ url_for("status_reply", status_id=tweet.id) }}">@</a>
                <a href="{{ url_for("status_replyall", status_id=tweet.id) }}">@@</a>
                <a href="{{ url_for("status_retweet", status_id=tweet.id) }}">RT</a>
                {% if tweet.favorited %}
                    <a href="{{ url_for("status_unfavorite", status_id=tweet.id) }}">UNFAV</a>
                {% else %}
                    <a href="{{ url_for("status_favorite", status_id=tweet.id) }}">FAV</a>
                {% endif %}
                {% if not tweet.deleted and tweet.user.screen_name == g.screen_name %}
                    {% set del_id = tweet.id %}
                {% elif tweet.retweet and tweet.retweet.user.screen_name == g.screen_name %}
                    {% set del_id = tweet.retweet.id %}
                {% endif %}
                {% if del_id %}
                    <a href="{{ url_for("status_delete", status_id=del_id) }}">DEL</a>
                {% endif %}
                {% set del_id = 0 %}
            </span>
        </div>
        <div class="item-content">
            <div class="item-text">
                <p>{{ tweet.text|safe }}</p>
            </div>
            {% if tweet.entities %}
                {% for media in tweet.entities.media %}
                    <div class="item-pic">
                        <a href="{{ media.original_url }}">
                            <img class="preview" src="{{ media.preview_url }}"/>
                        </a>
                    </div>
                {% endfor %}
            {% endif %}
        </div>
        <div class="item-footer">
            <a href="{{ url_for("status", status_id=tweet.id) }}#t{{ tweet.id }}"
               class="time">{{ render_created_at(tweet.created_at) }}</a>
            <span class="small">
                from {{ tweet.source|safe }}
                {% if tweet.in_reply_to_status_id %}
                    <a href="{{ url_for("status", status_id=tweet.id) }}#t{{ tweet.id }}">&gt;&gt;</a>
                {% endif %}
                {% if tweet.retweet %}
                    <br/>
                    <a href="{{ url_for("status", status_id=tweet.retweet.id) }}">
                        <span class="time">{{ render_created_at(tweet.retweet.created_at) }}</span>
                        retweeted
                    </a>
                    by
                    <a href="{{ url_for("user", screen_name=tweet.retweet.user.screen_name) }}">
                        {{ tweet.retweet.user.screen_name }}
                    </a>
                    from {{ tweet.retweet.source|safe }}
                    {% if tweet.retweet_count > 1 %}
                        and {{ tweet.retweet_count - 1 }} other(s)
                    {% endif %}
                {% endif %}
            </span>
        </div>
    </div>
{%- endmacro %}
{% macro render_follow(result) -%}
    <div class="status shift">
        <div class="item-header">
            {% if result.sources_size == 1 %}
                <img class="avatar" src="{{ result.sources|first|item("profile_image_url_https") }}"/>
            {% endif %}
            <span class="bold">
                {% for source in result.sources %}
                    <a href="{{ url_for("user", screen_name=source.screen_name) }}">
                        {{ source.screen_name }}
                    </a>
                    {% if not loop.last %}
                        ,
                    {% endif %}
                {% endfor %}
            </span>
            followed
            {% if result.targets|first|item("screen_name") == g.screen_name %}
                you.
            {% else %}
                :
            {% endif %}
        </div>
        {% if result.targets|first|item("screen_name") != g.screen_name %}
            <div class="item-content">
                <ul>
                    {% for target in result.targets %}
                        <li>
                            <a href="{{ url_for("user", screen_name=target.screen_name) }}">
                                {{ target.screen_name }}
                            </a>
                            ({{ target.name }})
                        </li>
                    {% endfor %}
                </ul>
            </div>
        {% endif %}
        <div class="item-footer">
            <span class="time">{{ render_created_at(result.created_at) }}</span>
        </div>
    </div>
{%- endmacro %}
{% macro render_favorite(result) -%}
    <div class="status shift">
        <div class="item-header">
            {% if result.sources_size == 1 %}
                <img class="avatar" src="{{ result.sources|first|item("profile_image_url_https") }}"/>
            {% endif %}
            <span class="bold">
                {% for source in result.sources %}
                    <a href="{{ url_for("user", screen_name=source.screen_name) }}">
                        {{ source.screen_name }}
                    </a>
                    {% if not loop.last %}
                        ,
                    {% endif %}
                {% endfor %}
            </span>
            {% set tweet = prerender_tweet(result.targets|first) %}
            favorited
            {% if tweet.user.screen_name == g.screen_name %}
                your Tweet
            {% else %}
                <a href="{{ url_for("user", screen_name=tweet.user.screen_name) }}">
                    {{ tweet.user.screen_name }}
                </a>
                ({{ tweet.user.name }})
            {% endif %}
            :
        </div>
        <div class="item-content">
            <div class="item-text">
                {{ tweet.text|safe }}
            </div>
            {% if tweet.entities %}
                <div class="item-pic">
                    {% for media in tweet.entities.media %}
                        <a href="{{ media.original_url }}">
                            <img class="preview" src="{{ media.preview_url }}"/>
                        </a>
                        <br/>
                    {% endfor %}
                </div>
            {% endif %}
        </div>
        <div class="item-footer">
            <a href="{{ url_for("status", status_id=tweet.id) }}" class="time">
                {{ render_created_at(tweet.created_at) }}
            </a>
            <span class="small">
                from {{ tweet.source|safe }}
                {% if tweet.in_reply_to_status_id %}
                    <a href="{{ url_for("status", status_id=tweet.id) }}">&gt;&gt;</a>
                {% endif %}
            </span>
        </div>
    </div>
{%- endmacro %}
{% macro render_retweet(result) -%}
    <div class="status shift">
        <div class="item-header">
            {% if result.sources_size == 1 %}
                <img class="avatar" src="{{ result.sources|first|item("profile_image_url_https") }}"/>
            {% endif %}
            <span class="bold">
            {% for source in result.sources %}
                <a href="{{ url_for("user", screen_name=source.screen_name) }}">
                    {{ source.screen_name }}
                </a>
                {% if not loop.last %}
                    ,
                {% endif %}
            {% endfor %}
            </span>
            {% set tweet = prerender_tweet(result.target_objects|first) %}
            retweeted
            {% if tweet.user.screen_name == g.screen_name %}
                your Tweet
            {% else %}
                {{ tweet.user.screen_name }} ({{ tweet.user.name }})
            {% endif %}
            :
        </div>
        <div class="item-content">
            <div class="item-text">
                {{ tweet.text|safe }}
            </div>
            {% if tweet.entities %}
                <div class="item-pic">
                    {% for media in tweet.entities.media %}
                        <a href="{{ media.original_url }}">
                            <img class="preview" src="{{ media.preview_url }}"/>
                        </a>
                        <br/>
                    {% endfor %}
                </div>
            {% endif %}
        </div>
        <div class="item-footer">
            <a href="{{ url_for("status", status_id=tweet.id) }}" class="time">
                {{ render_created_at(tweet.created_at) }}
            </a>
            <span class="small">
                from {{ tweet.source|safe }}
                {% if tweet.in_reply_to_status_id %}
                    <a href="{{ url_for("status", status_id=tweet.id) }}">&gt;&gt;</a>
                {% endif %}
            </span>
        </div>
    </div>
{%- endmacro %}
{% macro render_list_member_added(result) -%}
    <span class="avatar">
    </span>
    <div class="status shift">
        <div class="item-header">
            {% if result.sources_size == 1 %}
                <img src="{{ result.sources|first|item("profile_image_url_https") }}"/>
            {% endif %}
            <span class="bold">
                {% for source in result.sources %}
                    <a href="{{ url_for("user", screen_name=source.screen_name) }}">
                        {{ source.screen_name }}
                    </a>
                    {% if not loop.last %}
                        ,
                    {% endif %}
                {% endfor %}
            </span>
            added
            {% if result.targets|first|item("screen_name") == g.screen_name %}
                you.
            {% else %}
                {% for target in result.targets %}
                    <br/>
                    <a href="{{ url_for("user", screen_name=target.screen_name) }}">
                        {{ target.screen_name }}
                    </a>
                    ({{ target.name }})
                {% endfor %}
            {% endif %}
            to list
            <a href="{{ result.target_objects|first|item("uri") }}">
                {{ result.target_objects|first|item("full_name") }}
            </a>
        </div>
        <div class="item-footer">
            <span class="time">{{ render_created_at(result.created_at) }}</span>
        </div>
    </div>
{%- endmacro %}
